<template>
    <div class="left">
        <button @click="flyDefaault">UE初始场景</button>
        <h3>动态创建Actor</h3>
        <div>
            <input type="text" v-model="path">
            <button @click="createESUnrealActor">创建自定Actor</button>
        </div>

        <h3>绑定场景现有Actor</h3>

        <div>
            <input type="text" v-model="tag">
            <button @click="createESUnrealActorFromTag">创建自定Actor</button>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { Message } from "earthsdk-ui";
import { ESUnrealActor } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
import getMyProjectManager from '@/scripts/getMyProjectManager';
const myProjectManager = getMyProjectManager();
const path = ref("Blueprint'/Game/BasicContent/Alarm/BP_Alarm_Circle.BP_Alarm_Circle'")
const tag = ref('cube')

// 根据资产路径动态创建资产
const createESUnrealActor = () => {
    if (myProjectManager.activeViewer.typeName != "ESUeViewer") {
        Message.warning("请先切换到UE视口下")
        return
    }
    if (!path.value) {
        Message.warning("没有引用路径")
        return
    }
    const sceneObj = myProjectManager.createSceneObject(ESUnrealActor)
    sceneObj.editing = true
    sceneObj.actorClass = path.value

}

// 根据tag标签绑定场景中已有的actor
const createESUnrealActorFromTag = () => {
    if (myProjectManager.activeViewer.typeName != "ESUeViewer") {
        Message.warning("请先切换到UE视口下")
        return
    }
    if (!tag.value) {
        Message.warning("tag标签不能为空")
        return
    }

    myProjectManager.activeViewer.getObjectByInfo({ actorTag: tag.value }).then(res => {
        if (!res) {
            alert('该tag无效或者重复');
            return
        } else {
            const actor = myProjectManager.createSceneObject(ESUnrealActor)
            // actorTag唯一标识
            actor.actorTag = tag.value
            // 位置
            actor.position = res.position
            // 姿态
            actor.rotation = res.rotation
            // 高亮
            actor.highlight = true
            // 编辑
            actor.editing = true
        }
    })
}

const flyDefaault = () => {
    if (myProjectManager.activeViewer.typeName != "ESUeViewer") {
        Message.warning("请先切换到UE视口下")
        return
    }
    myProjectManager.activeViewer.defaultCameraFlyIn(2)
}




</script>

<style scoped>
.left {
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    background: url(../../assets/left/kuang.png) no-repeat;
    background-size: 100% 100%;
    display: flex;
    justify-content: flex-start;
    flex-direction: column;
    align-items: center;
    color: #fff;
}



hr {
    width: 90%;
}
</style>